//
//  XQFindViewController.swift
//  XiaoQiQiaoSwift
//
//  Created by tech-lab on 2016/11/24.
//  Copyright © 2016年 校企桥. All rights reserved.
//

import UIKit

class XQFindViewController: XQBaseViewController,UITableViewDataSource,UITableViewDelegate {

    private  var tableView = UITableView()

    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "发现"
        // Do any additional setup after loading the view.
        self.navigationItem.leftBarButtonItem = nil

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

    override func setRootView() {
       
        self.tableView = UITableView.init(frame:  CGRect.zero, style: .grouped)
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.showsVerticalScrollIndicator = false
        self.view.addSubview(self.tableView)
        
        tableView.snp.makeConstraints { (make) in
            make.left.equalTo(self.view.snp.left)
            make.right.equalTo(self.view.snp.right)
            make.top.equalTo(self.view.snp.top)
            make.bottom.equalTo(self.view.snp.bottom)
        }

        self.tableView .register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 4
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 || section == 3 {
            return 1
        }else{
            return 2
        }
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        if cell == nil {
            cell = UITableViewCell.init(style: .value2, reuseIdentifier: "cell")
        }
        
        switch indexPath.section {
        case 0:
            cell?.imageView?.image = UIImage.init(named: "find1")
            cell?.textLabel?.text = "今日头条"
            break
        case 1:
            if indexPath.row == 0 {
                cell?.imageView?.image = UIImage.init(named: "find2")
                cell?.textLabel?.text = "交流广场"
            }else{
                cell?.imageView?.image = UIImage.init(named: "find3")
                cell?.textLabel?.text = "精英圈"
            }
            break
        case 2:
            if indexPath.row == 0 {
                cell?.imageView?.image = UIImage.init(named: "find4")
                cell?.textLabel?.text = "签到"
            }else{
                cell?.imageView?.image = UIImage.init(named: "find5")
                cell?.textLabel?.text = "扫一扫"
            }
            break
        case 3:
            cell?.imageView?.image = UIImage.init(named: "find6")
            cell?.textLabel?.text = "邀请朋友"
            break
        default:
            break
        }
        
        
        
        return cell!
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
}
